﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace PeisongWeb
{
    public partial class buyer_customerList :buyerPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("EB", 1))
                {
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        void rptBind()
        {
            int companyid = logic.customer.getCompanyId();
            StringBuilder where = new StringBuilder();
            where.Append("companyId=" + companyid);
            if (txt_username.Value.Trim() != "")
                where.AppendFormat(" and [username] = '{0}'", txt_username.Value.Trim());
            if (txt_phone.Value.Trim() != "")
                where.AppendFormat(" and [phone] like '%{0}%'", txt_phone.Value.Trim());
            DataSet ds = logic.customer.select(where.ToString(), "customerId desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }
        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (Request.Headers["Accept"] != "*/*")
            {
                if (e.CommandName == "Del")
                {
                    int customerId = Convert.ToInt32(e.CommandArgument);
                    string infor;
                    logic.customer.delete(customerId);
                    rptBind();
                    infor = "删除成功！";
                    Library.Script.ClientMsg(infor);
                }
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }

        protected void btn_select_Click(object sender, EventArgs e)
        {
            rptBind();
        }
    }
}
